<!DOCTYPE html>
<!-- saved from url=(0066)http://wap.js.10086.cn/hyl/CAC/wpactivity/hxhzyItem/hxhzyItem.html -->
<html>
<head lang=en>
    <title>条形码扫描示例</title>
    <meta content="text/html; charset=UTF-8" http-equiv=Content-Type>
    <meta name=viewport
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;">
    <meta name=apple-mobile-web-app-capable content=yes>
    <meta name=apple-mobile-web-app-status-bar-style content=black>
    <meta name=GENERATOR content="MShtml 8.00.6001.23588">
    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="js/util.js"></script>
    <script type="text/javascript" src="js/quagga.min.js"></script>
    <script type="text/javascript" src="js/LocalResizeIMG.js"></script>
    <script type="text/javascript" src="js/patch/mobileBUGFix.mini.js"></script>
    <script type="text/javascript">

        if (document.documentElement.clientWidth / 7.5 <= 100) {
            document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + 'px';
        } else {
            document.documentElement.style.fontSize = 100 + 'px';
        }

        $(document).ready(function () {

            //文件上传
            $.each($('#sform input:file'), function (index, item) {
                //文件压缩
                $(item).localResizeIMG({
                    //width : 800,
                    quality: 1,
                    before: function () {
                        util.showMask();
                    },
                    success: function (result) {
                        var imgData = result.clearBase64;
                        Quagga.decodeSingle({
                            //解码方式，与条形码的编码方式有关
                            decoder: {
                                readers: ["code_128_reader", "ean_reader", "ean_8_reader", "code_39_reader", "code_39_vin_reader", "codabar_reader", "upc_reader", "upc_e_reader", "i2of5_reader"] // List of active readers
                            },
                            locate: true, // try to locate the barcode in the image
                            src: 'data:image/jpg;base64,' + imgData // or 'data:image/jpg;base64,' + data
                        }, function (result) {
                            if (result) {
                                if (result.codeResult) {
                                    $("#result").val(result.codeResult.code);
                                    $("#info").show();
                                    var code = result.codeResult.code;

                                } else {
                                    $("#result").val("");
                                    alert("未扫码成功，请重新扫码!");
                                }
                            } else {
                                alert("挂了!");
                                $("#result").val("");
                            }
                            util.removeMask();
                        });
                    }
                });
            });
            $("#aa").click(function () {
                var code = 111
                $.ajax({
                    type: "get",//指定请求方式
                    url: "getData?code=" + code, //请求路径
                    dataType: "json",//指定返回字符串以json格式返回,若不指定则以字符串方式返回(js识别不了的json)
                    success: function (result) {//进入success里,jquery已经把服务端传来的字符串解析到result里的 所以这里不需要加上result.responseText
                        $("#info").show();
                        $("#id").text(result.id)
                        $("#id2").text(result.id2)
                        $("#id3").text(result.id3)
                        $("#id4").text(result.id4)
                        $("#id5").text(result.id5)
                    },
                    error: function (result) {//response.status=500进入error方法里 参数:result代表是整个response对象
                        alert(result.responseText);//拿到response的传输的文本
                    }
                });
            });

        });

    </script>
</head>
<body>
<div>
    <form id="sform" method="post" name="sform" enctype="multipart/form-data">
        <p>
            <span style="font-size: 14px;"><label id="scan_code">条码：</label></span>
            <span><input class="infoInput"
                         id="result" style="width: 120px;" type="text" placeholder="" readonly="readonly"/></span>
            <input type="button" class="upload-btn" value="扫码" onclick="$('#code').click();"/>
            <input id="code" class="pad10 b-f" style="display: none;" type="file" accept="image/*"/>
        </p>
    </form>
</div>
<input id="aa" type="button" value="点我"/>
<div id="info" style="display: none">
    <table border="1">
        <tr>
            <td>January</td>
            <td id="id">$100</td>
        </tr>
        <tr>
            <td>January</td>
            <td id="id2">$100</td>
        </tr>
        <tr>
            <td>January</td>
            <td id="id3">$100</td>
        </tr>
        <tr>
            <td>January</td>
            <td id="id4">$100</td>
        </tr>
        <tr>
            <td>January</td>
            <td id="id5">$100</td>
        </tr>
    </table>
</div>
</body>
</html>
<script>
</script>